package fr.emn.integration.synthese.controle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.JOptionPane;

import fr.emn.integration.synthese.abstraction.Cours;
import fr.emn.integration.synthese.abstraction.Groupe;
import fr.emn.integration.synthese.presentation.GroupeDialog;

public class ControlJButtonSaveGroupe implements ActionListener {

	private Cours modele;
	private boolean creation;
	private GroupeDialog parent;

	public ControlJButtonSaveGroupe(GroupeDialog parent, Cours modele,
			boolean creation) {
		this.modele = modele;
		this.parent = parent;
		this.creation = creation;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (parent.getId()!=-1) {
			Groupe g = new Groupe(modele.getModuleCourante(), parent.getId(),
					parent.getEncadrant());
			try {
				modele.saveGroupe(g, creation);
				parent.setVisible(false);
			} catch (SQLException e1) {
				JOptionPane.showMessageDialog(parent, "On ne peut pas!", "Erreur!",
						JOptionPane.ERROR_MESSAGE);
			}
		}
	}

}
